package com.zf.museum.controller;

import com.zf.museum.bean.Result;
import com.zf.museum.model.Administrator;
import com.zf.museum.service.AdministratorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Api(description = "管理员")
@RestController
@RequestMapping("/administrator")
public class AdministratorController {

    @Autowired
    private AdministratorService administratorService;

    @PostMapping("/login")
    public Result login(@RequestParam("account") String account , @RequestParam("password") String password) {
        return administratorService.login(account, password);
    }

    @ApiOperation(value = "修改密码", notes = "前端发来修改的密码")
    @PostMapping("/update")
    @RequiresRoles("admin")
    public Result update(@RequestParam("password") String password, @RequestParam("account") String account) {

        return administratorService.update(password, account);
    }

    @PostMapping("/addAdmin")
    @RequiresRoles("admin")
    public Result addAdmin(@RequestParam("password") String password, @RequestParam("account") String account) {

        return administratorService.addAdmin(account, password);
    }
}
